import 'package:flutter/material.dart';
import 'package:macnov/utils/colorUtil.dart';
import 'package:macnov/utils/constant.dart';

class BudgetDelPanel extends StatefulWidget {
  final OnVoidSuccess cancelCallback;
  final OnVoidSuccess confirmCallback;

  const BudgetDelPanel({Key key, this.cancelCallback, this.confirmCallback}) : super(key: key);


  @override
  _BudgetDelPanelState createState() =>
      _BudgetDelPanelState(cancelCallback,confirmCallback);
}

class _BudgetDelPanelState extends State<BudgetDelPanel> {
  bool check1 = false;
  bool check2 = false;
  bool check3 = false;
  bool checkAll = false;

  final OnVoidSuccess cancelCallback;
  final OnVoidSuccess confirmCallback;

  _BudgetDelPanelState(this.cancelCallback, this.confirmCallback);

  _cancel() {
    Navigator.pop(context);
  }

  _confirm() {
    if (checkAll) {
      _cancel();
      confirmCallback();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 20),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(bottom: 25),
            child: Center(
              child: Text(
                'DELETE BUDGET',
                textAlign: TextAlign.center,
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(15, 20, 15, 10),
            child: RichText(
              text: TextSpan(
                  text: 'Warning:',
                  style: TextStyle(color: ColorsUtil.hexColor(0xcc2636)),
                  children: <TextSpan>[
                    TextSpan(
                        text:
                            ' you are about to remove and prevent spending for these people and cards:',
                        style: TextStyle(color: Colors.black87))
                  ]),
            ),
          ),
          new CheckboxListTile(
            title: const Text(
                'All transactions in this budget will be locked and cannot be moved to other budgets.'),
            value: this.check1,
            onChanged: (bool value) {
              setState(() {
                this.check1 = !this.check1;
                this.checkAll = this.check1 && this.check2 && this.check3;
              });
            },
          ),
          new CheckboxListTile(
            title: const Text('All member’s unspent funds will be returned.'),
            value: this.check2,
            onChanged: (bool value) {
              setState(() {
                this.check2 = !this.check2;
                this.checkAll = this.check1 && this.check2 && this.check3;
              });
            },
          ),
          new CheckboxListTile(
            title: const Text(
                'All virtual cards will be disabled for this budget. You can reassign them to an active budget later.'),
            value: this.check3,
            onChanged: (bool value) {
              setState(() {
                this.check3 = !this.check3;
                this.checkAll = this.check1 && this.check2 && this.check3;
              });
            },
          ),
          Padding(
            padding: EdgeInsets.only(top: 20),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                FlatButton(
                  child: Text('CANCEL'),
                  onPressed: _cancel,
                ),
                RaisedButton(
                  color: this.checkAll
                      ? ColorsUtil.hexColor(0xcc2636)
                      : Colors.grey,
                  child: Text(
                    'DELETE BUDGET',
                    style: TextStyle(color: Colors.white),
                  ),
                  onPressed: _confirm,
                  shape: StadiumBorder(),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
